classdef rexp
    % rexp  Wrapper for Regular Expressions (rexp Objects).
    %
    % Backend IRIS class.
    % No help provided.
    
    % -IRIS Toolbox.
    % -Copyright (c) 2007-2015 IRIS Solutions Team.
    
    
    properties
        String = '';
    end
    
    
    methods
        function This = rexp(varargin)
            if isempty(varargin)
                return
            end
            if length(varargin) == 1 && isrexp(varargin{1})
                This = varargin{1};
                return
            end
            if ischar(varargin{1})
                This.String = varargin{1};
            end
        end
    end
    
    
%**************************************************************************

    
    methods
        function varargout = char(This)
            varargout{1} = This.String;
        end
        
        
        function varargout = isempty(This,varargin)
            [varargout{1:nargout}] = isempty(This.String,varargin{:});
        end
        
        
        function varargout = length(This,varargin)
            [varargout{1:nargout}] = length(This.String,varargin{:});
        end
        
        
        function varargout = size(This,varargin)
            [varargout{1:nargout}] = size(This.String,varargin{:});
        end
        
        
        function varargout = strcmp(varargin)
            [varargout{1:nargout}] = apply(@strcmp,varargin{:});
        end
        
        
        function varargout = strcmpi(varargin)
            [varargout{1:nargout}] = apply(@strcmpi,varargin{:});
        end
        
        
        function varargout = strncmp(varargin)
            [varargout{1:nargout}] = apply(@strncmp,varargin{:});

        end
        
        
        function varargout = strncmpi(varargin)
            [varargout{1:nargout}] = apply(@strncmpi,varargin{:});

        end
        
        
        function This = strrep(This,varargin)
            This.String = strrep(This.String,varargin{:});
        end
        
        
        function This = strtrim(This,varargin)
            This.String = strtrim(This.String,varargin{:});
        end
        
        
        function varargout = regexp(varargin)
            [varargout{1:nargout}] = apply(@regexp,varargin{:});

        end
        
        
        function varargout = regexprep(varargin)
            [varargout{1:nargout}] = apply(@regexprep,varargin{:});
        end
        
        
        function varargout = regexprepi(varargin)
            [varargout{1:nargout}] = apply(@regexprepi,varargin{:});
        end
        
        
        function varargout = regexptranslate(varargin)
            [varargout{1:nargout}] = apply(@regexptranslate,varargin{:});
            varargout{1} = rexp(varargout{1});
        end
        
                
        function varargout = sprintf(varargin)
            [varargout{1:nargout}] = apply(@sprintf,varargin{:});
        end
        
        
        function varargout = apply(Fn,varargin)
            ix = cellfun(@(x) isrexp(x),varargin);
            for i = find(ix)
                varargin{i} = varargin{i}.String;
            end 
            [varargout{1:nargout}] = Fn(varargin{:});
        end        
    end
    
    
%**************************************************************************

    
    methods
        function K = end(This,varargin)
            K = length(This.String);
        end
        
        
        function Flag = eq(varargin)
            ix = cellfun(@(x) isrexp(x),varargin);
            for i = find(ix)
                varargin{i} = varargin{i}.String;
            end 
            Flag = eq(varargin{:});
        end
        
        
        function This = subsref(This,varargin)
            This.String = subsref(This.String,varargin{:});
        end
        
        
        function This = subsasgn(This,varargin)
            This.String = subsasgn(This.String,varargin{:});
        end
    end
end
